<template>
    <div>
        <!--查询条件start --111s-->
        <el-form :inline="true" :model="query" class="query-form" size="small">
            <el-form-item>
                <el-button type="primary" icon="el-icon-edit" @click.native="handleForm()">添加</el-button>
            </el-form-item>
            <el-form-item>
                <el-date-picker v-model="createTime" type="datetimerange" :picker-options="pickerOptions" range-separator="-" start-placeholder="开始日期"
                end-placeholder="结束日期" align="left" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
                :default-time="['00:00:00','23:59:59']" @change="dateChange"></el-date-picker>
            </el-form-item>
            <el-form-item class="query-form-item">
                <el-input v-model="query.content" placeholder="请输入商品名称" prefix-icon="el-icon-search" @keyup.enter.native="onSubmit"
                clearable></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-refresh" @click="onRest"></el-button>
                <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
            </el-form-item>

            <el-form-item label="上架状态">
                <el-select v-model="query.onshelfstatus" placeholder="请选择" @change="shelfstatus" clearable>
                    <el-option label="全部" value=''></el-option>
                    <el-option label="下架" value='0'></el-option>
                    <el-option label="上架" value='1'></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="分类：">
                <el-form-item label="一级分类">
                    <el-select v-model="query.topcategoryid" placeholder="请选择" @change="topchange()" clearable>
                        <el-option
                            v-for="(item,index) in category"
                            :key="index"
                            :label="item.topcategoryname"
                            :value="item.topcategoryid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="二级分类">
                    <el-select v-model="query.secondarycategoryid" placeholder="请选择" clearable @change="secondchange()">
                        <el-option
                            v-for="(item,index) in busCommoditySecondaryCategoryList"
                            :key="index"
                            :label="item.topcategoryname"
                            :value="item.topcategoryid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="三级分类">
                    <el-select v-model="query.thirdcategoryid" placeholder="请选择" clearable>
                        <el-option
                            v-for="(item,index) in busCommodityThirdCategoryList"
                            :key="index"
                            :label="item.topcategoryname"
                            :value="item.topcategoryid">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form-item>
        </el-form>

        <!--列表start --222s-->
        <el-table ref="multipleTable" v-loading="loading" :data="list" :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
            @selection-change="handleSelectionChange"  border>
            <el-table-column label="序号" type="selection" align="center" width="50"> </el-table-column>
            <el-table-column label="商品ID" prop="commodityid" width="50" align="center"/>
            <el-table-column label="商品图片" prop="commodityicon" align="center" width="150">
                <template slot-scope="scope">
                    <el-popover v-if="scope.row.commodityicon" placement="right" trigger="hover">
                        <img :src="scope.row.commodityicon" style="width:400px;border-radius:3px;">
                        <img slot="reference" :src="scope.row.commodityicon" style="max-height: 80px;max-width: 50px;border-radius:5px;">
                    </el-popover>
                    <span v-else>-</span>
                </template>
            </el-table-column>
            <el-table-column label="商品名称" prop="commodityname" width="150" align="center"/>
            <el-table-column label="平台/品牌名称" prop="companyName" width="150" align="center"/>
            <el-table-column label="一级分类" prop="topcategoryname" width="150" align="center"/>
            <el-table-column label="二级分类" prop="secondarycategoryname" width="150" align="center"/>
            <el-table-column label="三级分类" prop="thirdcategoryname" width="150" align="center"/>
            <el-table-column label="库存" prop="commoditynum" width="100" align="center"/>
            <el-table-column label="操作" width="240" align="center">
                <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click.native="detailForm(scope.$index, scope.row)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--列表end --222e-->
        <div class="left-container">
            <el-button type="danger" size="small" @click="delGroup()">删除已选</el-button>
            <transition name="el-fade-in-linear">
                <el-button size="small" @click="toggleSelection()" v-show="cancelToggle">取消选择</el-button>
            </transition>
        </div>
        <!--分页模块start-->
        <el-pagination
            class="pagination-container"
            background
            :page-size="query.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total,sizes,prev, pager, next, jumper"
            :current-page="query.currentPage"
            :page-sizes="[5,10, 20, 30, 50]"
            :total="totalNumber"
        ></el-pagination>
        <!--分页模块end-->

        <!--查看弹框-->
        <el-dialog title="查看详情" :visible.sync="detailVisible" :before-close="hideDetailForm" width="80%" top="5vh" v-dialogDrag>
        <el-form :model="formData" label-width="140px">
            <el-form-item label="商品名称:">
                <input v-model="formData.commodityname" type="text" readonly>
            </el-form-item>
            <el-form-item label="商品分类:">
                <span>{{formData.topcategoryname+","+formData.secondarycategoryname+","+formData.thirdcategoryname}}</span>
            </el-form-item>
            <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">
                <el-form-item label="代理价:" style="width:30%;display: inline-block;">
                    <input v-model="formData.commodityoldprice" type="text" readonly>
                </el-form-item>
                <el-form-item label="零售价:" style="margin-left:80px; width:30%;display: inline-block;">
                    <input v-model="formData.commodityprice" type="text" readonly>
                </el-form-item>
            </el-form-item>

            <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">
                <el-form-item label="添加时间:" style="width:30%;display: inline-block;">
                    <input :value="formData.createtime |formatDateStr('yyyy-MM-dd') " type="text" readonly>
                </el-form-item>
                <el-form-item label="商品ID:" style="margin-left:80px; width:30%;display: inline-block;">
                    <input v-model="formData.commodityid" type="text" readonly>
                </el-form-item>
            </el-form-item>

            <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">
                <el-form-item label="商品评论:" style="width:30%;display: inline-block;">
                    <el-button @click="lookcomment(formData.commodityid)">查看</el-button>
                </el-form-item>
                <el-form-item label="上架:" style="margin-left:80px; width:30%;display: inline-block;">
                <div>
                    <el-switch v-model="formData.onshelfstatus" active-color="#13ce66" inactive-color="#ff4949"
                     active-value='1' inactive-value='0' @change="onshelfschange(formData)">
                    </el-switch>
                </div>
                </el-form-item>
            </el-form-item>

            <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">
                <el-form-item label="封面图:" style="width:30%;display: inline-block">
                    <!--<img :src="formData.userpic" alt style="width: 60px;height: 50px">-->
                    <el-popover v-if="formData.commodityicon" placement="right" trigger="hover">
                    <img :src="formData.commodityicon" style="width:400px;border-radius:3px;">
                    <img slot="reference" :src="formData.commodityicon" style="max-height: 80px;max-width: 50px;border-radius:5px;" >
                    </el-popover>
                    <span v-else>-</span>
                </el-form-item>
                <el-form-item label="库存:" style="margin-left:80px; width:30%;display: inline-block;">
                    <input v-model="formData.commoditynum" type="text" readonly>
                </el-form-item>
            </el-form-item>
            <el-form-item label-width="120px" label="商品资质认证" style="background: #e1e1e1"></el-form-item>
                <span v-if="categoryTemplate != [] && categoryTemplate != null">
                    <h3 class="thrTitle">{{categoryTemplate.name || ""}}</h3>
                    <el-form-item :label="item.fieldname+'：'" :prop="'fieldname'+index" v-for="(item,index) in categoryTemplate.templateItemFormList" :key="item.id">
                    <input type="hidden" v-model="item.fieldvalue">
                    <el-input v-model="formData4[item.fieldname]" @input="onInput()" @change="changeInput(item)" v-if="item.fieldtype == '文字'" type="text" :placeholder="'请填写'+item.fieldname" disabled></el-input>
                    <el-input v-model="formData4[item.fieldname]" @input="onInput()" @change="changeInput(item)" v-if="item.fieldtype == '数字'" type="number" :placeholder="'请填写'+item.fieldname" disabled></el-input>
                    <el-popover v-if="item.fieldtype == '图片'" placement="right" trigger="hover">
                        <img :src="item.fieldvalue" style="width:400px;border-radius:3px;">
                        <img slot="reference" :src="item.fieldvalue" style="max-height: 80px;max-width: 150px;border-radius:5px;">
                    </el-popover>
                    </el-form-item>
                </span>
                <!--商品规格-->
            <el-table ref="multipleTable" v-loading="loading" :data="parameterlist" :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
                @selection-change="handleSelectionChange" border>
                <el-table-column label="商品图片" width="100"  align="center">
                    <template slot-scope="scope">
                        <el-popover v-if="scope.row.inventorypic" placement="right" trigger="hover">
                            <img :src="scope.row.inventorypic" style="width:400px;border-radius:3px;">
                            <img slot="reference" :src="scope.row.inventorypic" style="max-height: 80px;max-width: 50px;border-radius:5px;">
                        </el-popover>
                        <span v-else>-</span>
                    </template>
                </el-table-column>
                <el-table-column label="规格参数" align="center">
                    <el-table-column v-for="(item,index) in inputData" :key="index" :label='item.key' width="150" align="center">
                        <template slot-scope="scope">
                            <div v-if="scope.row.splist!==undefined">
                                <el-select v-model="scope.row.splist[index]" placeholder="请选择" disabled  ref="sel" >
                                    <el-option v-for="(it,ind) in (item.val.split(','))" :key="ind" :label="it" :value="it"></el-option>
                                </el-select>
                            </div>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column label="成本价" prop="costprice"  align="center"/>
                <el-table-column label="代理价" prop="primaryagentprice"  align="center"/>
                <el-table-column label="经销价" prop="secondaryagentprice"  align="center"/>
                <el-table-column label="分销价" prop="commodityprice"  align="center"/>
                <el-table-column label="零售价" prop="commodityoldprice" align="center"/>
                <el-table-column label="库存" prop="inventorynum"  align="center"/>
                <el-table-column label="操作" prop="inventorynum"  align="center">
                    <template slot-scope="scope">
                        <el-button  @click="addCar(scope.$index, scope.row)" type="info">添加到进货配单</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <el-form-item label="商品轮播图:">
                <div v-for="(item,index) in formData.commoditypiclist" :key="index" style="display:inline-block;">
                    <img :src="item" style="width:200px;border-radius:3px;margin-left: 5px;">
                </div>
            </el-form-item>
            <el-form-item label="商品详情:">
                <div v-html="formData.commoditydesc"></div>
            </el-form-item>
        </el-form>
    </el-dialog>
    </div>
</template>
<script>
    import {
        getList,
        getCategory,
        delBusCommodity,
        addBusCommodity,
        getBusWarehouseList,
        updateBusCommodity
    } from "../../api/buscommodity/buscommodity.js";
    import Tinymce from "../../components/Tinymce/index.vue";
    import {BASE_URL} from "../../config/app";
    import { quillEditor } from "vue-quill-editor"; //调用编辑器
    import 'quill/dist/quill.core.css';
    import 'quill/dist/quill.snow.css';
    import 'quill/dist/quill.bubble.css';
    import {getGoodsCertificationInfo} from "../../api/buscommodity/buscommodity";
    import {merchantsCommodityToExamine} from "../../api/classification/classification.js";
    import { updatePlatformCommodityInventory } from "../../api/buscommodity/commodityInventory";

    /*用作表单的数据初始化*/
    const formJson = {
        commodityid: "",//商品id
        commodityname: "",//商品名称
        recommendstatus: 0,//商品'0不推荐1推荐',
        onshelfstatus: 1,//商品 0全部，  1不上架 2上架',
        commodityicon: "",//商品图片
        commodityprice: "",// 分销价    decimal(20,2),
        commodityoldprice: "",//成本价    decimal(20,2),
        commodityfrom: "",// 货源地
        topcategoryname: "",//一级分类
        secondarycategoryname: "",//二级分类
        thirdcategoryname: "",//三级分类
        commoditytype:"",
        commoditynum: "",// 库存
        createtime: "",// 添加时间
        commoditydesc: "",//商品描述
        commoditypiclist: [],//图片
        piclist: "", //图片列表
        videopic:"" , //视频地址
        commoditystatus:"",//审核状态
        /**/
        topcategoryid: "",//一级分类id',
        secondarycategoryid: "",//二级分类id',
        thirdcategoryid: "",// 三级分类id,
        inids: "" ,//参数id
        param:"",
        inputdata:"",//全部参数
        certificationcontent:"",
        belongtype:"",
        companyName:""
    };
    /*富文本*/
    const toolbarOptions = [
        ['bold', 'italic', 'underline', 'strike'],    // toggled buttons
        [{'header': 1}, {'header': 2}],        // custom button values
        [{'list': 'ordered'}, {'list': 'bullet'}],
        [{'indent': '-1'}, {'indent': '+1'}],     // outdent/indent
        [{'direction': 'rtl'}],             // text direction
        [{'size': ['small', false, 'large', 'huge']}], // custom dropdown
        [{'header': [1, 2, 3, 4, 5, 6, false]}],
        [{'color': []}, {'background': []}],     // dropdown with defaults from theme
        [{'font': []}],
        [{'align': []}],
        ['link', 'image'],
        ['clean']

    ]
    export default {
        components: {
            Tinymce ,
            quillEditor
        },
        data() {
            return {
                radio: '1',
                options: [
                    {
                        value: 0,
                        label: '代理商品'
                    },
                    {
                        value: 1,
                        label: '代理自营商品'
                    },
                ],
                pickerOptions: {//快速选择日期
                    shortcuts: [
                        {
                            text: "最近一周",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 7
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近一个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 30
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近三个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 90
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近六个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 180
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        }
                    ]
                },
                formData4: {
                    // 第四步表单
                    storename: null, // 店铺名称
                    enterinfoid: null, // 主键
                    certificationcontent: null, // 商品分类模板
                    topcategoryid: null, // 一级商品分类id
                    secondarycategoryid: null, // 二级商品分类id
                    categoryid: null // 三级商品分类id
                },
                aaaaa:"",
                bbbbb:0,
                query: {//查询条件
                    content: "",
                    starttime: "",
                    endtime: "",
                    onshelfstatus: '',//0全部，  1不上架 2上架
                    recommendstatus: "",//0不推荐1推荐
                    currentPage: 1,
                    pageSize: 5,
                    topcategoryid: "", //一级
                    secondarycategoryid: "",//二级
                    thirdcategoryid: ""//三级
                },
                productionList:{},//商品的添加列表
                productionNumber:{},//商品增加的数量
                formData: formJson,//新增或修改的对象
                commoditypiclist:[],
                formName: '',
                formMap: {
                    add: "添加",
                    edit: "编辑",
                    detail: "查看",
                    examine:"审核",
                    inventoryEdit: "库存管理"
                },
                inventoryVisible: false, //库存管理编辑显示
                inventoryChange: false,
                inventorySubmitFlag: false,
                uploadUrl: BASE_URL + '/goldendays-currency/tool/uploadpro',//上传图片
                uploadvideo: BASE_URL + "/tool/uploadVideo",//上传视频
                uploadData: [],//[{name:"12",url:"http://localhost/maotianxiaupload/common/2019-08-23/MH1566545692219_mid.jpg"}], // 图片data
                vuploadData:[], //视频
                uploadData1: {}, // 图片data
                curRowIndex: 0,//图片row
                createTime: [],//选择日期时需要的model
                list: [],//列表集合
                parameterlist: [], //add参数list
                //savadd参数list
                category: [],//分类列表
                buswarehouse: [],//仓库列表
                busCommoditySecondaryCategoryList: [], //二级
                busCommodityThirdCategoryList: [],//三级
                categoryobj: {},//分类列表
                SecondaryCategoryobj: {}, //二级
                ThirdCategoryobj: {},//三级
                inputData: [],// 循环创建input存值
                totalNumber: 0,//分页总页数
                formVisible: false,//添加编辑显示
                loading: true,//列表加载
                dis:true,//不可点击
                formLoading: false,//表单提交加载
                allLoding: false,//全屏加载
                cancelToggle: false,
                detailVisible: false,//查看
                examineVisible:false,
                classification: false,
                dialogFormVisible: false,
                formSumbitLoding: false, //表单提交加载
                multipleSelection: [], //多选集合
                rejectreason: "",
                commodityid:"",
                categoryTemplate: [], // 商品类目模板
                quillUpdateImg: false, // 根据图片上传状态来确定是否显示loading动画，刚开始是false,不显示
                // content: null,
                editorOption: {
                    placeholder: '',
                    theme: 'snow', // or 'bubble'
                    modules: {
                        toolbar: {
                            container: toolbarOptions,
                            handlers: {
                                'image': function (value) {
                                    if (value) {
                                        // 触发input框选择图片文件
                                        document.querySelector('.edituploader input').click()
                                    } else {
                                        this.quill.format('image', false);
                                    }
                                }
                            }
                        }
                    }
                },
                header: {
                    // token: sessionStorage.token
                }

            };
        },
        watch: {},
        methods: {

            addCar(i,val){
             console.log(i)
             console.log(val)
             this.productionNumber = val//数据详情框里面的数据
             let that = this
             console.log(this.productionList)//数据第一列表里面的数据
             let copy = Object.assign({},this.productionList,this.productionNumber)//合并两个对象的方法// console.log(copy)
             let listArr =[]
             listArr.push(copy)
             localStorage.setItem("listArr",JSON.stringify(listArr))
             this.$router.push({
                path: "puchasingOrder",
            //     // name:"代理商品进货配单",
            //     params:{
            //         commodityicon:copy.commodityicon,//商品图片
            //         commodityname:copy.commodityname,//商品名称
            //         companyName:copy.companyName,//品牌名称
            //         inventory:copy.inventory,//商品规格
            //         costprice:copy.costprice,//成本价
            //         primaryagentprice:copy.primaryagentprice,//代理价
            //         secondaryagentprice:copy.secondaryagentprice,//经销价
            //         commodityprice:copy.commodityprice,//分销价
            //         commodityoldprice:copy.commodityoldprice,//零售价
            //         buyfromnum:copy.buyfromnum,//库存
            //         commodityid:copy.commodityid, //商品id
            //     }
            })

            },
            hideInventoryForm() {
                // 更改值
                this.inventoryVisible = !this.inventoryVisible;
                this.inventorySubmitFlag=false;
                return true;
            },

            //图片上传成功
            handleFieldSuccess(response, file, fileList, index, key, item) {
                if (response.status === 1) {
                    this[index][key] = response.data;
                    if (item || item == 0) {
                        // item.fieldvalue = this.formData4[item.fieldname];
                        this.categoryTemplate.templateItemFormList[
                            item
                            ].fieldvalue = this.formData4[key];
                        // console.log(this.categoryTemplate.templateItemFormList[item]);
                        // console.log(this.formData4);
                    }
                    return;
                }
                this.$message.error("上传文件报错");
            },
            // 移除图片
            handleFieldPicRemove(file, fileList, index, key, item) {
                this[index][key] = null;
                if (item || item == 0) {
                    // item.fieldvalue = null;
                    this.categoryTemplate.templateItemFormList[
                        item
                        ].fieldvalue = null;
                    // console.log(this.categoryTemplate.templateItemFormList[item]);
                    // console.log(this.formData4);
                }
            },
            examine(type) {
                if (type == 2) {
                    this.dialogFormVisible = true;
                    return false;
                }
                // 1 通过 2 驳回
                let data = {
                    commodityid: this.formData.commodityid,
                    commoditystatus: 1
                };
                this.commodityToExamine(data);
            },
            commodityToExamine(data) {
                merchantsCommodityToExamine(data)
                    .then(response => {
                        // console.log(response);
                        if (response.code != 0) {
                            this.$message.error(response.message);
                            return false;
                        }
                        this.dialogAddOrEdit = false;
                        this.examineVisible = false;
                        this.dialogFormVisible = false;
                        this.$message.success(response.message);
                        this.getList();
                        setTimeout(() => {
                            this.loading = false;
                        }, 0.3 * 1000);
                    })
                    .catch(() => {
                        this.loading = false;
                    });
            },
            //驳回
            reject() {
                if (!this.rejectreason) {
                    this.$message.error("请填写驳回原因！");
                    return false;
                }
                // 1 通过 2 驳回
                let data = {
                    commodityid: this.formData.commodityid,
                    commoditystatus: 2,
                    rejectreason: this.rejectreason
                };
                this.dialogFormVisible = false;
                this.commodityToExamine(data);
            },
            //图片上传成功
            // handleFormDataSuccess(response, file, fileList, index, key, item) {
            //     if (response.status === 1) {
            //         this[index][key] = response.data;
            //         if (item) {
            //             item.fieldvalue = this.formData4[item.fieldname];
            //         }
            //         return;
            //     }
            //     this.$message.error("上传文件报错");
            // },
            // 强制刷新input
            onInput() {
                this.$forceUpdate();
            },
            // 模板input监听
            changeInput(val) {
                val.fieldvalue = this.formData4[val.fieldname];
                // console.log(this.formData4);
            },
            onEditorChange({editor, html, text}) {//内容改变事件
                // console.log("---内容改变事件---")
                this.formData.commoditydesc = html
                // console.log(html)
            },
            // 富文本图片上传前
            // beforeUpload() {
            //     // 显示loading动画
            //     this.quillUpdateImg = true
            // },

            // imguploadSuccess(response, file) {
            //     // res为图片服务器返回的数据
            //     // 获取富文本组件实例
            //     // console.log(response);
            //     let quill = this.$refs.myQuillEditor.quill

            //     // 如果上传成功
            //     if (response.status === 1 ) {
            //         let filePath = response.data;
            //         // 获取光标所在位置
            //         let length = quill.getSelection().index;
            //         // 插入图片 res.url为服务器返回的图片地址
            //         quill.insertEmbed(length, 'image', filePath)
            //         // 调整光标到最后
            //         quill.setSelection(length + 1)
            //         this.$message.success('图片插入成功')
            //     } else {
            //         this.$message.error('图片插入失败')
            //     }
            //     // loading动画消失
            //     this.quillUpdateImg = false

            // },
            // 富文本图片上传失败
            // uploadError() {
            //     // loading动画消失
            //     this.quillUpdateImg = false
            //     this.$message.error('图片插入失败')
            // },


            //table列表参数
            paramchange(e,i,row,index,it){

                console.info(i+"=="+index+"---------"+this.inputData)
                let data={};
                this.$set(data,it.key,e);
                this.parameterlist[i].savparameterlist[index]=data;
                console.info(this.parameterlist[i].savparameterlist);
            },

            //仓库
            warechange(e) {
                for(let i=0;i<this.buswarehouse.length;i++){
                    if(e===this.buswarehouse[i].warehouseid){
                        this.formData.commodityfrom = this.buswarehouse[i].warehousename;
                        this.formData.warehouseid = this.buswarehouse[i].warehouseid;
                    }
                }

                // alert(e.warehousename)
            },
            arrNumber(arr){
                var arr_number = {};
                for(var i = 0 ; i < arr.length ; i++){
                    if(arr_number[arr[i]]){
                        arr_number[arr[i]]++
                    }
                    else{
                        arr_number[arr[i]] = 1 ;
                    }
                }
                return arr_number ;
            },
            formSubmit() {
                console.log(JSON.stringify(this.parameterlist));
                let plist = this.parameterlist;
                if(plist!=null && plist.length==0){
                    return false;
                }
                for (let i = 0; i < plist.length; i++) {
                    let jsonval = JSON.stringify(plist[i].savparameterlist);

                    // var json = [{dd:'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}];
                    let json=plist[i].savparameterlist
                    let indata={};
                    for(var j=0,l=json.length;j<l;j++){
                        for(var key in json[j]){
                            // alert(key+':'+json[j][key]);
                            this.$set(indata, key, json[j][key]);
                        }
                    }
                    plist[i].inventory=JSON.stringify(indata);
                    plist[i].secinventory = jsonval;

                }
                //商品资质认证

                //零售价
                this.formData.commodityprice = plist[0].commodityoldprice;
                //代理价
                this.formData.commodityoldprice =plist[0].primaryagentprice;
                this.$refs["ruleForm"].validate(valid => {
                    if (valid) {
                        /*添加商品*/
                        // alert(mids);
                        if(this.formData.commoditypiclist&&this.formData.commoditypiclist.length!==0){
                            this.formData.commodityicon=this.formData.commoditypiclist[0];
                            this.formData.piclist = this.formData.commoditypiclist.join(",");
                        }
                        //alert("===="+JSON.stringify(this.formData.commoditypiclist.length)+"=="+this.formData.piclist)
                        var inventorylistobj=[];
                        if(plist){
                            let num=0;
                            for (let i=0;i< plist.length;i++) {
                                let nm=1;
                                num+=(plist[i].inventorynum)*(nm);
                                inventorylistobj.push(plist[i].inventory);
                                var inventory=  plist[i].inventory.substring(1,plist[i].inventory.length-1);
                                var inventorylist=inventory.split(":");
                                console.info(inventorylist[1].length)
                                if(inventorylist[1].length<3){
                                    this.$message.warning("请完善商品规格信息！");
                                    return false;
                                }
                                if(plist[i].costprice<1){
                                    this.$message.warning("请完善商品规格信息！");
                                    return false;
                                }
                                if(plist[i].commodityprice <1){
                                    this.$message.warning("请完善商品规格信息！");
                                    return false;
                                }

                                if(plist[i].commodityoldprice <1){
                                    this.$message.warning("请完善商品规格信息！");
                                    return false;
                                }
                                if(plist[i].secondaryagentprice <1){
                                    this.$message.warning("请完善商品规格信息！");
                                    return false;
                                }
                                if(plist[i].primaryagentprice <1){
                                    this.$message.warning("请完善商品规格信息！");
                                    return false;
                                }
                            }

                            this.formData.commoditynum=num;
                        }
                        var inventoryojb= this.arrNumber(inventorylistobj);
                        console.info(inventoryojb)
                        for (let i = 0; i < plist.length; i++) {
                            var inventorycount=  inventoryojb[plist[i].inventory]
                            console.info(inventoryojb[plist[i].inventory])
                            if(inventorycount>1){
                                this.$message.warning("商品不可添加俩个及以上的相同规格！");
                                return false;
                            }
                        }
                        this.formData.param=JSON.stringify(plist);
                        // alert(JSON.stringify(this.plist));
                        this.formData.inputdata=JSON.stringify(this.inputData);
                        let flag = false;
                        var msg ="";
                        if(this.categoryTemplate==null ||  this.categoryTemplate==undefined) {
                            this.$message.warning("无商品模板！");
                            return false;
                        }
                        this.formData.certificationcontent = JSON.stringify(this.categoryTemplate);
                        if(this.categoryTemplate.templateItemFormList!=null&&this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach(item => {
                                    if((item.fieldvalue==null||item.fieldvalue=="")&& item.ismust==0){
                                        msg = item.fieldname;
                                        flag = true;
                                    }
                                }
                            );
                        }else{
                            this.$message.warning("无商品模板！");
                            return false;
                        }
                        if(flag){
                            this.$message({
                                message: msg+"不能为空！",
                                type: "warning"
                            });
                            return false;
                        }
                        var params = new URLSearchParams(this.formData);

                        this.dis=false;
                        addBusCommodity(params).then(response => {
                            this.formLoading = false;
                            if (response.code != 0) {
                                this.$message.error(response.message);
                                return false;
                            }
                            this.$message.success("操作成功");
                            this.uploadData = [];//图片
                            this.vuploadData=[];//视频

                            this.formData = {};
                            // this.$refs.tinymce.setContent("");


                            this.formLoading = false;
                            this.formVisible = false;

                            this.dis=true;
                            // 加载表格数据
                            this.getList();
                            // 清空表单
                            this.$refs["ruleForm"].resetFields();
                            //取消



                        }).catch(() => {
                            this.formLoading = false;
                            this.formVisible = false;
                            this.dis=true;
                        });

                    }
                });

            },


            // 图片上传
            // AvatarUpload(file) {
            //     this.fileName = file.name ? file.name : "";
            //     return false;
            // },
            // //图片上传成功
            // vhandleSuccess(response, file) {
            //     this.isSelect = false;
            //     if (response.status === 1) {
            //         const filePath = response.data;//视频地址
            //         // const vPath = response.content;//视频截图地址
            //         this.formData.videopic=filePath;
            //         // console.info(JSON.stringify(this.uploadData));
            //         return;
            //     }

            //     this.$message.error("上传文件报错");
            // },
            // 图片上传
            // vhandleChange(file) {
            //     this.fileName = file.name ? file.name : "";
            //     return false;
            // },
            //图片上传成功
            // handleSuccess(response, file) {
            //     console.info(response)
            //     console.info(this.formData.commoditypiclist)
            //     this.isSelect = false;
            //     if (response.status === 1) {
            //         const filePath = response.data;
            //         this.formData.commoditypiclist.push(filePath);
            //         console.info(JSON.stringify(this.uploadData));
            //         return;
            //     }

            //     this.$message.error("上传文件报错");
            // },
            // 图片上传
            handleChange(file) {
                this.fileName = file.name ? file.name : "";
                return false;
            },
            handlePicRemove(file,fileList) {
                console.info("file=" + file+"fileList:"+fileList)
                console.info("commoditypiclist"+JSON.stringify(this.formData.commoditypiclist))
                var url = "";
                url = file.url;
                for (var i = 0; i < this.formData.commoditypiclist.length; i++) {
                    if (url===this.formData.commoditypiclist[i]){
                        this.formData.commoditypiclist.splice(i, 1);
                        console.info("commoditypiclist9999999999"+JSON.stringify(this.formData.commoditypiclist))
                    }
                }
                for (var i = 0; i < this.uploadData.length; i++) {
                    if (url===this.uploadData[i].url){
                        this.uploadData.splice(i, 1);
                        console.info("commoditypiclist9999999999"+JSON.stringify(this.formData.commoditypiclist))

                    }
                }

                console.info(this.uploadData)
            },

            //添加参数
            addpara() {
                let param = {
                    inventoryid: "",//          bigint not null auto_increment,
                    commodityid: "",//          bigint,
                    inventory: "",//      规格参数      text,
                    secinventory:"",       //规格参数2
                    commodityprice: 0,//    分销价   decimal(20,2),
                    commodityoldprice: 0,//  零售价  decimal(20,2),
                    primaryagentprice: 0,//一级代理
                    secondaryagentprice: 0,//二级代理
                    costprice: 0,//成本价
                    inventorynum: 0,//      库存   int,
                    inventorypic: "",//   规格图片      varchar(200),
                    companytype: 0,//      单位    smallint comment '0:瓶 1箱 2:套',
                    boxnum: "",//      每箱瓶数         int comment '每箱瓶数',
                    savparameterlist: [],
                    splist:[]
                };
                let p = {
                    key: "",
                    val: ""
                };

                param.savparameterlist.push(p);
                this.parameterlist.push(param);
                console.info("++" + this.parameterlist[0].savparameterlist.val);
            },



            //查看评论
            lookcomment(v) {

                this.$router.push({path: '/commodity/comment', query: {cid: v}})
                // alert(v)
            },
            //add 隐藏表单
            hideForm() {
                // 更改值
                this.formVisible = !this.formVisible;
                // 清空表单
                this.$refs["ruleForm"].resetFields();

                this.query.warehousename = "";
                return true;
            },
            /* --------------*/
            //筛选上架
            shelfstatus() {
                this.query.currentPage = 1;
                this.getList();

            },
            //上架
            onshelfschange(row) {
                this.loading = true;
                var params = new URLSearchParams();
                params.append("commodityid", row.commodityid);
                params.append("onshelfstatus", row.onshelfstatus);
                updateBusCommodity(params)
                    .then(response => {
                        this.loading = false;
                        if (response.code) {
                            this.$message.error(response.message);
                            return false;
                        }
                        this.loading = false;
                        this.$message.success("更新成功");
                        // 刷新数据
                    })
                    .catch(() => {
                        this.loading = false;
                    });
            },
            //推荐
            recommendchange(row) {
                this.loading = true;
                var params = new URLSearchParams();
                params.append("commodityid", row.commodityid);
                params.append("recommendstatus", row.recommendstatus);
                updateBusCommodity(params)
                    .then(response => {
                        this.loading = false;
                        if (response.code) {
                            this.$message.error(response.message);
                            return false;
                        }
                        this.loading = false;
                        this.$message.success("更新成功");
                        // 刷新数据

                    })
                    .catch(() => {
                        this.loading = false;
                    });

            },
            // 添加显示表单
            handleForm() {
                this.categoryTemplate = [];
                this.formVisible = true;
                this.formName = "add"
                this.inputData=[];
                this.parameterlist=[];
                this.getBusWarehouse();

                this.uploadData=[];
                //this.commoditydesc=""//this.$refs.tinymce.setContent("");
                this.formData={
                    commodityid: "",//商品id
                    commodityname: "",//商品名称
                    recommendstatus: 0,//商品'0不推荐1推荐',
                    onshelfstatus: 1,//商品 0全部，  1不上架 2上架',
                    commodityicon: "",//商品图片
                    commodityprice: "",// 售价    decimal(20,2),
                    commodityoldprice: "",//商品原价    decimal(20,2),
                    commodityfrom: "",// 货源地
                    topcategoryname: "",//一级分类
                    secondarycategoryname: "",//二级分类
                    thirdcategoryname: "",//三级分类
                    primaryentitybillie:"",
                    seniorentitybillie:"",
                    commoditytype:"",
                    commoditynum: "",// 库存
                    createtime: "",// 添加时间
                    commoditydesc: "",//商品描述
                    commoditypiclist: [],//图片
                    piclist: "", //图片列表
                    videopic:"" , //视频地址

                    /**/
                    topcategoryid: "",//一级分类id',
                    secondarycategoryid: "",//二级分类id',
                    thirdcategoryid: "",// 三级分类id,

                    inids: "" ,//参数id
                    param:"",
                    inputdata:""//全部参数
                }
            },
            //显示 查看弹框
            detailForm(index, row) {
                // debugger;
                this.detailVisible = true;
                if (row !== null) {
                    this.inputData=[]
                    this.formData = Object.assign({}, row);
                    console.info(row)
                    this.productionList =row
                    console.info(this.formData )
                    this.formData.secondarycategoryid=row.secondarycategoryid;
                    this.formData.thirdcategoryid=row.thirdcategoryid;

                    if(row.certificationcontent!=null){
                        this.categoryTemplate = JSON.parse(row.certificationcontent);
                        this.formData.certificationcontent = JSON.parse(row.certificationcontent);
                        if(this.categoryTemplate.templateItemFormList!=null&&this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach(item => {
                                    // item.fieldvalue = this.formData4[item.fieldname];
                                    this.formData4[item.fieldname] = item.fieldvalue;
                                }
                            );
                        }
                    }
                    // this.formData.commoditytype=row.commoditytype+"";
                    if(row.inventorylist!=null&&row.inventorylist[0].inputdata!=null){
                        this.inputData=JSON.parse(row.inventorylist[0].inputdata);
                    }else{
                        let data={
                            key:"",
                            val:""
                        }
                        this.inputData.push(data);
                    }

                    this.getBusWarehouse();

                    if(row.commoditydesc){
                        //this.commoditydesc=row.commoditydesc;
                        // this.$refs.tinymce.setContent(row.commoditydesc);
                    }
                }
                let data=[];
                let pic=[];
                let vdata=[];
                let vpic=[];
                for (let i=0;i<row.commoditypiclist.length;i++){
                    let picdata=row.commoditypiclist[i];
                    if(picdata.recoursetype===0){
                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        data.push(obj);
                        pic.push(picdata.picurl)
                    }
                    if(picdata.recoursetype===1){

                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        vdata.push(obj);
                        vpic.push(picdata.picurl)
                    }
                }

                this.formData.videopic=vpic;
                this.vuploadData=vdata
                this.commoditypiclist=pic;
                this.formData.commoditypiclist=pic;
                this.uploadData=data;

                this.parameterlist=row.inventorylist;
                for(let i=0;i<this.parameterlist.length;i++){
                    let sav=[];
                    this.$set(this.parameterlist[i], "savparameterlist", sav);
                    this.$set(this.parameterlist[i], "splist", sav);

                    var a=this.parameterlist[i].inventory.indexOf("}");
                    var b=this.parameterlist[i].inventory.substring(1,a)
                    var a1=b.split(",");
                    var splist1=[];
                    for (let c=0;c<a1.length;c++) {
                        var s=a1[c].split(":")[1].substring(1,a1[c].split(":")[1].length-1);
                        splist1.push(s)
                    }
                    this.parameterlist[i].splist=(splist1);
                    this.parameterlist[i].savparameterlist=JSON.parse(this.parameterlist[i].secinventory);

                    this.parameterlist[i].companytype= this.parameterlist[i].companytype.toString();
                }
                //参数
                let sav=[];
                if(this.parameterlist!=null&&this.parameterlist.length>0){

                    for(let i=0;i<this.parameterlist.length;i++){
                        let pdata=JSON.parse(this.parameterlist[i].secinventory);

                        console.info(pdata)

                        for (let i=0;i<pdata.length;i++) {
                            let mdata=pdata[i]
                            for (let v in mdata){
                                let data={
                                    key:v,
                                    val:mdata[v].toString()
                                }
                                sav.push(mdata[v].toString());
                            }
                        }
                        this.parameterlist.savparameterlist=pdata;
                    }
                    this.parameterlist.splist=sav;
                }
                this.formName = "detail";
            },
            //显示 查看弹框
            inventoryForm(index, row) {
                // debugger;
                //   console.info('---row--Data:'+ JSON.stringify(row));
                this.inventoryVisible = true;
                this.inventoryChange=false;
                this.inventorySubmitFlag=false;
                if (row !== null) {
                    this.inputData=[]
                    this.formData = Object.assign({}, row);
                    this.formData.secondarycategoryid=row.secondarycategoryid;
                    this.formData.thirdcategoryid=row.thirdcategoryid;

                    if(row.certificationcontent!=null){
                        this.categoryTemplate = JSON.parse(row.certificationcontent);
                        this.formData.certificationcontent = JSON.parse(row.certificationcontent);
                        if(this.categoryTemplate.templateItemFormList!=null&&this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach(item => {
                                    // item.fieldvalue = this.formData4[item.fieldname];
                                    this.formData4[item.fieldname] = item.fieldvalue;
                                }
                            );
                        }
                    }
                    // this.formData.commoditytype=row.commoditytype+"";
                    if(row.inventorylist!=null && row.inventorylist[0].inputdata!=null){
                        this.inputData=JSON.parse(row.inventorylist[0].inputdata);
                    }else{
                        let data={
                            key:"",
                            val:""
                        }
                        this.inputData.push(data);
                    }

                    this.getBusWarehouse();

                    if(row.commoditydesc){
                        //this.commoditydesc=row.commoditydesc;
                        // this.$refs.tinymce.setContent(row.commoditydesc);
                    }
                }
                let data=[];
                let pic=[];
                let vdata=[];
                let vpic=[];
                for (let i=0;i<row.commoditypiclist.length;i++){
                    let picdata=row.commoditypiclist[i];
                    if(picdata.recoursetype===0){
                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        data.push(obj);
                        pic.push(picdata.picurl)
                    }
                    if(picdata.recoursetype===1){

                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        vdata.push(obj);
                        vpic.push(picdata.picurl)
                    }
                }

                this.formData.videopic=vpic;
                this.vuploadData=vdata
                this.commoditypiclist=pic;
                this.formData.commoditypiclist=pic;
                this.uploadData=data;

                this.parameterlist=row.inventorylist;
                for(let i=0;i<this.parameterlist.length;i++){
                    let sav=[];
                    this.$set(this.parameterlist[i], "savparameterlist", sav);
                    this.$set(this.parameterlist[i], "splist", sav);

                    var a=this.parameterlist[i].inventory.indexOf("}");
                    var b=this.parameterlist[i].inventory.substring(1,a)
                    var a1=b.split(",");
                    var splist1=[];
                    for (let c=0;c<a1.length;c++) {
                        var s=a1[c].split(":")[1].substring(1,a1[c].split(":")[1].length-1);
                        splist1.push(s)
                    }
                    this.parameterlist[i].splist=(splist1);
                    this.parameterlist[i].savparameterlist=JSON.parse(this.parameterlist[i].secinventory);
                    this.parameterlist[i].companytype= this.parameterlist[i].companytype.toString();
                }
                //参数
                let sav=[];
                if(this.parameterlist!=null&&this.parameterlist.length>0){
                    for(let i=0;i<this.parameterlist.length;i++){
                        let pdata=JSON.parse(this.parameterlist[i].secinventory);
                        for (let i=0;i<pdata.length;i++) {
                            let mdata=pdata[i]
                            for (let v in mdata){
                                let data={
                                    key:v,
                                    val:mdata[v].toString()
                                }
                                sav.push(mdata[v].toString());
                            }
                        }
                        this.parameterlist.savparameterlist=pdata;
                    }
                    this.parameterlist.splist=sav;
                }
                this.formName = "inventoryEdit";
                // console.info('--parameterlist-data:'+ JSON.stringify(this.parameterlist));
                // console.info('commodityid: ' + this.formData.commodityid);
            },
            //显示 审核弹框
            examineForm(index, row) {
                this.examineVisible = true;
                if (row !== null) {
                    this.inputData=[]
                    this.formData = Object.assign({}, row);
                    console.info(row)
                    console.info(this.formData )
                    this.formData.secondarycategoryid=row.secondarycategoryid;
                    this.formData.thirdcategoryid=row.thirdcategoryid;
                    if(row.certificationcontent!=null){
                        this.categoryTemplate = JSON.parse(row.certificationcontent);
                        this.formData.certificationcontent = JSON.parse(row.certificationcontent);
                        if(this.categoryTemplate.templateItemFormList!=null&&this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach(item => {
                                    // item.fieldvalue = this.formData4[item.fieldname];
                                    this.formData4[item.fieldname] = item.fieldvalue;
                                }
                            );
                        }
                    }
                    // this.formData.commoditytype=row.commoditytype+"";
                    if(row.inventorylist!=null&&row.inventorylist[0].inputdata!=null){
                        this.inputData=JSON.parse(row.inventorylist[0].inputdata);
                    }else{
                        let data={
                            key:"",
                            val:""
                        }
                        this.inputData.push(data);
                    }

                    this.getBusWarehouse();

                    if(row.commoditydesc){
                        //this.commoditydesc=row.commoditydesc;
                        // this.$refs.tinymce.setContent(row.commoditydesc);
                    }
                }
                let data=[];
                let pic=[];
                let vdata=[];
                let vpic=[];
                for (let i=0;i<row.commoditypiclist.length;i++){
                    let picdata=row.commoditypiclist[i];
                    if(picdata.recoursetype===0){
                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        data.push(obj);
                        pic.push(picdata.picurl)
                    }
                    if(picdata.recoursetype===1){

                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        vdata.push(obj);
                        vpic.push(picdata.picurl)
                    }
                }

                this.formData.videopic=vpic;
                this.vuploadData=vdata
                this.commoditypiclist=pic;
                this.formData.commoditypiclist=pic;
                this.uploadData=data;

                this.parameterlist=row.inventorylist;
                for(let i=0;i<this.parameterlist.length;i++){
                    let sav=[];
                    this.$set(this.parameterlist[i], "savparameterlist", sav);
                    this.$set(this.parameterlist[i], "splist", sav);

                    var a=this.parameterlist[i].inventory.indexOf("}");
                    var b=this.parameterlist[i].inventory.substring(1,a)
                    var a1=b.split(",");
                    var splist1=[];
                    for (let c=0;c<a1.length;c++) {
                        var s=a1[c].split(":")[1].substring(1,a1[c].split(":")[1].length-1);
                        splist1.push(s)
                    }
                    this.parameterlist[i].splist=(splist1);
                    this.parameterlist[i].savparameterlist=JSON.parse(this.parameterlist[i].secinventory);

                    this.parameterlist[i].companytype= this.parameterlist[i].companytype.toString();
                }
                //参数
                let sav=[];
                if(this.parameterlist!=null&&this.parameterlist.length>0){

                    for(let i=0;i<this.parameterlist.length;i++){
                        let pdata=JSON.parse(this.parameterlist[i].secinventory);

                        console.info(pdata)

                        for (let i=0;i<pdata.length;i++) {
                            let mdata=pdata[i]
                            for (let v in mdata){
                                let data={
                                    key:v,
                                    val:mdata[v].toString()
                                }
                                sav.push(mdata[v].toString());
                            }
                        }
                        this.parameterlist.savparameterlist=pdata;
                    }
                    this.parameterlist.splist=sav;
                }
                this.formName = "examine";
            },
            // 隐藏详情弹框
            hideDetailForm() {
                // 更改值
                this.detailVisible = !this.detailVisible;
                // 清空表单
                this.formData={};
                return true;
            },
            hideExamineForm() {
                // 更改值
                this.examineVisible = !this.examineVisible;
                // 清空表单
                // this.formData={};
                return true;
            },

            hideclassification() {
                this.classification = !this.classification;
                return true;
            },

            //编辑
            editForm(index, row) {
                this.formData = Object.assign({}, formJson);
                if (row !== null) {
                    this.inputData=[]
                    this.formData = Object.assign({}, row);
                    console.info(row)
                    console.info(this.formData )
                    this.formData.secondarycategoryid=row.secondarycategoryid;
                    this.formData.thirdcategoryid=row.thirdcategoryid;
                    if(row.certificationcontent!=null){
                        this.categoryTemplate = JSON.parse(row.certificationcontent);
                        this.formData.certificationcontent = JSON.parse(row.certificationcontent);
                        if(this.categoryTemplate.templateItemFormList!=null&&this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach(item => {
                                    // item.fieldvalue = this.formData4[item.fieldname];
                                    this.formData4[item.fieldname] = item.fieldvalue;
                                }
                            );
                        }
                    }

                    // this.formData.commoditytype=row.commoditytype+"";
                    if(row.inventorylist!=null&& row.inventorylist.length>0&&row.inventorylist[0].inputdata!=null){
                        this.inputData=JSON.parse(row.inventorylist[0].inputdata);
                    }else{
                        let data={
                            key:"",
                            val:""
                        }
                        this.inputData.push(data);
                    }

                    this.getBusWarehouse();

                    if(row.commoditydesc){
                        //this.commoditydesc=row.commoditydesc;
                        // this.$refs.tinymce.setContent(row.commoditydesc);
                    }
                }
                let data=[];
                let pic=[];
                let vdata=[];
                let vpic=[];
                for (let i=0;i<row.commoditypiclist.length;i++){
                    let picdata=row.commoditypiclist[i];
                    if(picdata.recoursetype===0){
                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        data.push(obj);
                        pic.push(picdata.picurl)
                    }
                    if(picdata.recoursetype===1){

                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        vdata.push(obj);
                        vpic.push(picdata.picurl)
                    }
                }

                this.formData.videopic=vpic;
                this.vuploadData=vdata
                this.commoditypiclist=pic;
                this.formData.commoditypiclist=pic;
                this.uploadData=data;

                this.parameterlist=row.inventorylist;
                for(let i=0;i<this.parameterlist.length;i++){
                    let sav=[];
                    this.$set(this.parameterlist[i], "savparameterlist", sav);
                    this.$set(this.parameterlist[i], "splist", sav);

                    var a=this.parameterlist[i].inventory.indexOf("}");
                    var b=this.parameterlist[i].inventory.substring(1,a)
                    var a1=b.split(",");
                    var splist1=[];
                    for (let c=0;c<a1.length;c++) {
                        var s=a1[c].split(":")[1].substring(1,a1[c].split(":")[1].length-1);
                        splist1.push(s)
                    }
                    this.parameterlist[i].splist=(splist1);
                    this.parameterlist[i].savparameterlist=JSON.parse(this.parameterlist[i].secinventory);

                    this.parameterlist[i].companytype= this.parameterlist[i].companytype.toString();
                }
                //参数
                let sav=[];
                if(this.parameterlist!=null&&this.parameterlist.length>0){

                    for(let i=0;i<this.parameterlist.length;i++){
                        let pdata=JSON.parse(this.parameterlist[i].secinventory);

                        console.info(pdata)

                        for (let i=0;i<pdata.length;i++) {
                            let mdata=pdata[i]
                            for (let v in mdata){
                                let data={
                                    key:v,
                                    val:mdata[v].toString()
                                }
                                sav.push(mdata[v].toString());
                            }
                        }
                        this.parameterlist.savparameterlist=pdata;
                    }
                    this.parameterlist.splist=sav;
                }
                console.info(this.formData)
                this.getBusWarehouse();
                this.topchange1();
                this.formData.secondarycategoryid=row.secondarycategoryid;
                this.secondchange1();
                this.formData.thirdcategoryid=row.thirdcategoryid;
                this.formName = "edit";
                this.formVisible = true;

            },

            /*获取列表事件*/
            getList() {
                this.loading = true;
                this.list = [];
                getList(this.query).then(response => {
                    if (response.code != 0) {
                        this.$message.error(response.message);
                        return false;
                    }
                    let datalist = response.data.list || []
                    if (datalist.length > 0) {
                        let mylist = datalist
                        for (var i = 0; i < mylist.length; i++) {
                            if (mylist[i].onshelfstatus != null) {
                                mylist[i].onshelfstatus = mylist[i].onshelfstatus.toString();
                            }
                            if (mylist[i].recommendstatus != null) {
                                mylist[i].recommendstatus = mylist[i].recommendstatus.toString();
                            }
                            if(mylist[i].belongtype==0){//平台
                                mylist[i].companyName="平台"
                            }
                        }
                        this.list = mylist

                        // console.info('row-data:'+ JSON.stringify(this.list));

                    }
                    // this.list = response.data.list || [];

                    this.totalNumber = response.data.totalNumber || 0;
                    setTimeout(() => {
                        this.loading = false;
                    }, 0.3 * 1000);
                }).catch(() => {
                    this.loading = false;
                    this.list = [];
                })
            },

            //一级
            topchange() {
                this.query.secondarycategoryid="";
                this.query.thirdcategoryid="";
                this.busCommoditySecondaryCategoryList=[];
                this.busCommodityThirdCategoryList=[]
                let query={
                    parentId: this.query.topcategoryid
                };
                if(this.query.topcategoryid){
                    getCategory(query)
                        .then(response => {
                            if (response.code) {
                                this.$message.error(response.message);
                            }
                            let data = response.data || [];
                            this.busCommoditySecondaryCategoryList = data;
                            setTimeout(() => {
                                this.loading = false;
                            }, 0.3 * 1000);
                        })
                        .catch(() => {
                            this.loading = false;
                            this.list = [];
                            this.totalNumber = 0;
                        });
                }
            },
            //二级
            secondchange() {
                this.query.thirdcategoryid="";
                this.busCommodityThirdCategoryList=[]
                let query={
                    parentId: this.query.secondarycategoryid
                };
                if(this.query.secondarycategoryid){
                    getCategory(query)
                        .then(response => {
                            if (response.code) {
                                this.$message.error(response.message);
                            }
                            let data = response.data || [];
                            this.busCommodityThirdCategoryList = data;
                            setTimeout(() => {
                                this.loading = false;
                            }, 0.3 * 1000);
                        })
                        .catch(() => {
                            this.loading = false;
                            this.list = [];
                            this.totalNumber = 0;
                        });
                }
            },

            //add一级
            topchange1() {
                this.formData.secondarycategoryid="";
                this.formData.thirdcategoryid="";
                this.busCommoditySecondaryCategoryList=[];
                this.busCommodityThirdCategoryList=[]
                let query={
                    parentId: this.formData.topcategoryid
                };

                if(this.formData.topcategoryid){
                    getCategory(query)
                        .then(response => {
                            if (response.code) {
                                this.$message.error(response.message);
                            }
                            let data = response.data || [];
                            this.busCommoditySecondaryCategoryList = data;
                            setTimeout(() => {
                                this.loading = false;
                            }, 0.3 * 1000);
                        })
                        .catch(() => {
                            this.loading = false;
                            this.list = [];
                            this.totalNumber = 0;
                        });
                }
            },
            //add二级
            secondchange1() {
                this.formData.thirdcategoryid="";
                this.busCommodityThirdCategoryList=[]
                let query={
                    parentId: this.formData.secondarycategoryid
                };
                if(this.formData.secondarycategoryid){
                    getCategory(query)
                        .then(response => {
                            if (response.code) {
                                this.$message.error(response.message);
                            }
                            let data = response.data || [];
                            this.busCommodityThirdCategoryList = data;
                            setTimeout(() => {
                                this.loading = false;
                            }, 0.3 * 1000);
                        })
                        .catch(() => {
                            this.loading = false;
                            this.list = [];
                            this.totalNumber = 0;
                        });
                }
            },
            thirdchange1() {

                for (var i = 0; i < this.busCommodityThirdCategoryList.length; i++) {
                    if (this.busCommodityThirdCategoryList[i].topcategoryid == this.formData.thirdcategoryid) {
                        this.ThirdCategoryobj = this.busCommodityThirdCategoryList[i];
                        if(this.ThirdCategoryobj.specification!=null){
                            let data = this.ThirdCategoryobj.specification.split(",");
                            let indata=[];
                            for (let i = 0; i < data.length; i++) {
                                let mydata = {
                                    key:"",
                                    val:""
                                };
                                mydata.key = data[i];
                                mydata.val = "";
                                indata.push(mydata);
                            }
                            this.inputData=indata;
                        }

                        this.formData.thirdcategoryname = this.busCommodityThirdCategoryList[i].topcategoryname
                        this.formData.thirdcategoryid = this.busCommodityThirdCategoryList[i].topcategoryid
                        this.classification = false;
                        break;
                    }
                }
                if(this.formData.thirdcategoryid){
                    this.getTemplate(this.formData.thirdcategoryid);

                }

            },
            getTemplate(thirdcategoryid) {
                this.categoryTemplate = [];
                this.loading = true;
                const formData = new FormData();
                formData.append("threeCategoryId", thirdcategoryid);
                getGoodsCertificationInfo(formData)

                    .then(response => {
                        console.log(response)
                        if (response.code) {
                            this.$message.error(response.message);
                            this.loading = false;
                        }
                        if (response.data.templateFromList.length == 0) {
                            this.loading = false;
                            this.categoryTemplate = [];
                            return false;
                        }
                        // if (this.initialTemplate.id == response.data.templateFromList[0].id) {
                        //     let template = JSON.stringify(this.initialTemplate);
                        //     this.categoryTemplate = JSON.parse(template);
                        //     this.loading = false;
                        //     return false;
                        // }
                        this.categoryTemplate = response.data.templateFromList[0];
                        if(this.categoryTemplate!=null && this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach(
                                item => {
                                    this.formData4[item.fieldname] = null;
                                }
                            );
                        }

                        setTimeout(() => {
                            this.loading = false;
                        }, 0.3 * 1000);
                    })
                    .catch(err => {
                        this.$message.error(err);
                        this.loading = false;
                    });
            },
            //获得分类
            getAllCategory() {
                getCategory()
                    .then(response => {
                        if (response.code) {
                            this.$message.error(response.message);
                        }
                        let data = response.data || [];
                        this.category = data;
                    })
                    .catch(() => {
                        this.category = [];
                    });
            },
            //获得仓库
            getBusWarehouse() {
                this.loading = true;
                // console.info("123")
                getBusWarehouseList()
                    .then(response => {
                        if (response.code) {
                            this.$message.error(response.message);
                        }
                        let data = response.data || [];

                        /*  for (let i=0;i<this.data.length;i++){
                              let mdata=this.data[i];
                              mdata.warehouseid=mdata.warehouseid.toString();
                          }*/
                        this.buswarehouse = data;
                        setTimeout(() => {
                            this.loading = false;
                        }, 0.3 * 1000);
                    })
                    .catch(() => {
                        this.loading = false;
                        this.list = [];
                        this.totalNumber = 0;
                    });
            },
            /*新增或者编辑提交事件*/
            formSumbit() {
                var ids = this.multipleSelection.map(item => item.commodityid).join(); //获取所有选中行的id组成的字符串，以逗号分隔
                if (ids == "") {
                    this.$message({
                        message: "请先选择",
                        type: "warning"
                    });
                    return;
                }

                this.$emit("on-select", ids, ids);

            },
            /*日期选择事件*/
            dateChange(val) {
                if (val == null) {
                    this.query.starttime = "";
                    this.query.endtime = "";
                } else {
                    this.query.starttime = val[0];
                    this.query.endtime = val[1];
                    this.query.currentPage = 1;
                }
                this.getList();
            },
            /*列表查询条件事件*/
            onSubmit() {
                this.query.currentPage = 1;
                this.getList();
            },

            /*刷新*/
            onRest() {
                //刷新事件需要重置查询条件
                this.createTime = [];
                this.query = {
                    currentPage: 1,
                    pageSize: 5,
                };
                this.getList();
            },

            /*点击页数*/
            handleCurrentChange(val) {
                this.query.currentPage = val;
                this.getList();
            },

            /*选择每页条数【10,20,30,40,50】*/
            handleSizeChange(val) {
                this.query.pageSize = val;
                this.getList();
            },

            /*取消全选事件*/
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }

            },

            /*列表复选框选择事件*/
            handleSelectionChange(val) {
                this.multipleSelection = val;
                if (val == "") {
                    this.cancelToggle = false;
                    return;
                }
                this.cancelToggle = true;
            },

            /*全选删除事件*/
            delGroup() {
                var ids = this.multipleSelection.map(item => item.commodityid).join(); //获取所有选中行的id组成的字符串，以逗号分隔
                if (ids == "") {
                    this.$message({
                        message: "请先选择",
                        type: "warning"
                    });
                    return;
                }
                this.handleDel(ids);
            },

            /*选中事件*/
            handleDel(ids) {
                console.info()
                if (ids) {
                    this.$confirm("确认要删除吗?", "提示", {
                        type: "warning"
                    })
                        .then(() => {
                            this.loading = true;
                            var params = new URLSearchParams();
                            params.append("ids", ids);
                            delBusCommodity(params)
                                .then(response => {
                                    this.loading = false;
                                    if (response.code) {
                                        this.$message.error(response.message);
                                        return false;
                                    }
                                    this.$message.success("删除成功");
                                    // 刷新数据
                                    //this.list.splice(index, 1);
                                    this.getList();
                                })
                                .catch(() => {
                                    this.loading = false;
                                });
                        })
                        .catch(() => {
                            this.$message.warning("已取消");
                        });
                }
            },
            //提交库存修改数据
            inventoryFormSubmit() {
                // console.log('---更新后的库存'+ JSON.stringify(this.parameterlist));
                //用户未改变库存值，不提交
                if(!this.inventoryChange){
                    return false;
                }
                this.inventorySubmitFlag=true;
                let plist = this.parameterlist;
                let paramsData=[];
                for (let i = 0; i < plist.length; i++) {
                    let inventoryObj={
                        inventoryId:"",
                        inventoryNum:"",
                        commodityId: ''
                    }
                    inventoryObj.inventoryId  = plist[i].inventoryid;
                    inventoryObj.inventoryNum = plist[i].inventorynum;
                    inventoryObj.commodityId = this.formData.commodityid
                    paramsData.push(inventoryObj);
                }
                var params = new URLSearchParams();
                params.append("paramsData", JSON.stringify(paramsData));
                // console.log('库存更新提交的数据：'+ JSON.stringify(paramsData));

                updatePlatformCommodityInventory(params).then((response) => {
                    this.formLoading = true;
                    if (response.code != 0) {
                        this.$message.error(response.message);
                        return false;
                    }
                    this.$message.success("操作成功");

                    this.formData = {};
                    this.formLoading = false;
                    this.inventoryVisible = false;
                    this.inventoryChange = false;
                    this.inventorySubmitFlag= false;
                    this.dis = true;
                    // 加载表格数据
                    this.getList();
                }).catch(() => {
                    this.formLoading = false;
                    this.inventoryVisible = false;
                    this.dis = true;
                });
            },
            openRejectDialog(row) {
                this.$alert(row.rejectreason, '拒绝原因', {
                    confirmButtonText: '确定'
                });
            },

        },

        created() {
            this.getList();
            this.getAllCategory();

        }
    }

</script>
<style type="text/css">
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .avatar-uploader-icon {
        font-size: 21px;
        color: #8c939d;
        width: 50px;
        height: 50px;
        line-height: 178px;
        text-align: center;
    }

    .avatar {
        width: 178px;
        height: 178px;
        display: block;}
    .thrTitle {
        margin-left: 60px;
        font-size: 16px;
        font-weight: 600;
    }
</style>


